home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Mac OS USB DDK / Examples / CompositeClassDriver / CompositeDriverDescription.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-10  |  6.8 KB  |  230 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CompositeDriverDescription.c
  3.  
  4.     Contains:    Composite Class Driver Definition Header
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "CompositeClassDriver.h"
  19. #include "CompositeClassVersion.h"
  20.  
  21. usbCompositePBStruct newInterfacesPB;
  22.  
  23.  
  24. OSStatus CompositeDriverInitInterface(
  25.             UInt32                         interfaceNum, 
  26.             USBInterfaceDescriptor        *interfaceDesc, 
  27.             USBDeviceDescriptor            *deviceDesc, 
  28.             USBDeviceRef                 device);
  29.  
  30. //------------------------------------------------------
  31. //
  32. //    This is the driver description structure that the expert looks for first.
  33. //  If it's here, the information within is used to match the driver
  34. //  to the device whose descriptor was passed to the expert.
  35. //    Information in this block is also used by the expert when an
  36. //  entry is created in the Name Registry.
  37. //
  38. //------------------------------------------------------
  39. USBDriverDescription    TheUSBDriverDescription = 
  40. {
  41.     // Signature info
  42.     kTheUSBDriverDescriptionSignature,
  43.     kInitialUSBDriverDescriptor,
  44.     
  45.     // Device Info
  46.     0,                                        // vendor = not device specific
  47.     0,                                        // product = not device specific
  48.     0,                                        // version of product = not device specific
  49.     0,                                        // protocol = not device specific
  50.     
  51.     // Interface Info    (* I don't think this would always be required...*)                
  52.     0,                                        // Configuration Value
  53.     0,                                        // Interface Number
  54.     0,                                        // Interface Class
  55.     0,                                         // Interface SubClass
  56.     0,                                        // Interface Protocol
  57.         
  58.     
  59.     // Driver Info
  60.     "\pUSBCompositeDevice"kCMPStringVersShort,    // Driver name for Name Registry
  61.     kUSBCompositeClass,                            // Device Class  (from USBDeviceDefines.h)
  62.     kUSBCompositeSubClass,                        // Device Subclass 
  63.     kCMPHexMajorVers, 
  64.     kCMPHexMinorVers, 
  65.     kCMPCurrentRelease, 
  66.     kCMPReleaseStage,                        // version of driver
  67.     
  68.     // Driver Loading Info
  69.     kUSBDoNotMatchInterface                    // Please don't load us as an interface driver.
  70. };
  71.  
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,                // Version of this structure
  75.     CompositeDriverValidateHW,                // Hardware Validation Procedure
  76.     CompositeDriverInitialize,                // Initialization Procedure
  77.     CompositeDriverInitInterface,            // Interface Initialization Procedure
  78.     CompositeDriverFinalize,                // Finalization Procedure
  79.     CompositeDriverNotifyProc                // Driver Notification Procedure
  80. };
  81.  
  82. // hubDriverInitInterface function
  83. // Called to initialize driver for an individual interface - either by expert or
  84. // internally by driver
  85. OSStatus CompositeDriverInitInterface(
  86.             UInt32                         interfaceNum, 
  87.             USBInterfaceDescriptor        *interfaceDesc, 
  88.             USBDeviceDescriptor            *deviceDesc, 
  89.             USBDeviceRef                 device)
  90. {
  91. #pragma unused (interfaceNum)
  92. #pragma unused (interfaceDesc)
  93. #pragma unused (deviceDesc)
  94. #pragma unused (device)
  95.  
  96.     return (OSStatus)kUSBNoErr;
  97. }
  98.  
  99. OSStatus    CompositeDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (refcon)
  103.  
  104. OSStatus    myErr;
  105. OSStatus     status = kUSBNoErr;
  106. static    UInt32    interfacenum = 0;
  107.  
  108.     switch (notification)
  109.     {
  110.         case kNotifyDriverBeingRemoved:
  111.             newInterfacesPB.driverRemovalPending = true;
  112.             
  113.             if (newInterfacesPB.pb.usbRefcon & kCompletionPending)
  114.             {
  115.                 USBExpertStatus(newInterfacesPB.deviceRef, kCompositeDriverName": Waiting for transaction to complete", newInterfacesPB.pb.usbRefcon);
  116.                 status = kUSBDeviceBusy;
  117.             }
  118.             else
  119.             {
  120.                 if (interfacenum == 0)
  121.                     newInterfacesPB.pb.usbStatus = kUSBNoErr;
  122.                 
  123.                 if (newInterfacesPB.pb.usbStatus == kUSBPending)
  124.                 {
  125.                     USBExpertStatus(newInterfacesPB.deviceRef, kCompositeDriverName": Waiting for Dispose/Deallocate to complete", newInterfacesPB.pb.usbRefcon);
  126.                     status = kUSBDeviceBusy;
  127.                 }
  128.                 else
  129.                 {
  130.                     if (interfacenum < newInterfacesPB.interfaceCount)        
  131.                     {
  132.                         USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[interfacenum]);
  133.                         InitParamBlock(newInterfacesPB.interfaceRefArray[interfacenum], &newInterfacesPB.pb);
  134.                         newInterfacesPB.pb.usbRefcon = 0;             
  135.                         newInterfacesPB.pb.usbCompletion = (USBCompletion)kUSBNoCallBack;
  136.                         myErr = USBDisposeInterfaceRef(&newInterfacesPB.pb);
  137.                         if(immediateError(myErr))
  138.                         {
  139.                             USBExpertFatalError(newInterfacesPB.interfaceRefArray[interfacenum], kUSBInternalErr, kCompositeDriverName" - USBDisposeInterfaceRef - immediate error", myErr);
  140.                         }
  141.                         interfacenum++;
  142.                         status = kUSBDeviceBusy;
  143.                     }
  144.                     else
  145.                     {
  146.                         if (newInterfacesPB.pFullConfigDescriptor)
  147.                         {
  148.                             InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
  149.                             newInterfacesPB.pb.usbRefcon = 0;             
  150.                             newInterfacesPB.pb.usbBuffer = newInterfacesPB.pFullConfigDescriptor;        
  151.                             newInterfacesPB.pb.usbCompletion = (USBCompletion)kUSBNoCallBack;
  152.                             myErr = USBDeallocMem(&newInterfacesPB.pb);
  153.                             newInterfacesPB.pFullConfigDescriptor = nil;
  154.                             status = kUSBDeviceBusy;
  155.                         }
  156.                         else
  157.                         {
  158.                             status = kUSBNoErr;
  159.                         }
  160.                     }
  161.                 }
  162.             }
  163.             break;
  164.             
  165.         default:
  166.             break;
  167.     }
  168.     return status;
  169. }
  170.  
  171. // Hardware Validation
  172. // Called upon load by Expert
  173. OSStatus CompositeDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  174. {
  175. #pragma unused (device)
  176. #pragma unused (desc)
  177.  
  178.     return (OSStatus)kUSBNoErr;
  179. }
  180.  
  181. // Initialization function
  182. // Called upon load by Expert
  183. OSStatus     CompositeDriverInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  184. {
  185.     // don't let a race condition occur; prevent finalizing until we're all done.
  186.     DeviceInitialize(device, pDesc, busPowerAvailable);
  187.     return (OSStatus)kUSBNoErr;
  188. }
  189.  
  190. // Termination function
  191. // Called by Expert when driver is being shut down
  192. OSStatus CompositeDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  193. {
  194. #pragma unused (pDesc)
  195.  
  196.     USBExpertStatus(theDeviceRef, kCompositeDriverName" - Finalize", 0);
  197.     return (OSStatus)kUSBNoErr;
  198. }
  199.  
  200. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  201. {
  202. static Boolean beenThereDoneThat = false;
  203.  
  204.     if(beenThereDoneThat)
  205.     {
  206.         USBExpertFatalError(device, kUSBInternalErr, kCompositeDriverName" is not reentrant!", 0);
  207.         return;
  208.     }
  209.     beenThereDoneThat = true;
  210.     
  211.     newInterfacesPB.driverRemovalPending = false;
  212.     
  213.     newInterfacesPB.deviceRef = device;    
  214.     newInterfacesPB.deviceDescriptor = *pDeviceDescriptor;    
  215.     
  216.     newInterfacesPB.busPowerAvailable = busPowerAvailable;                            
  217.     newInterfacesPB.delayLevel = 0;                            
  218.     newInterfacesPB.transDepth = 0;                            
  219.     newInterfacesPB.retryCount = kCompositeRetryCount;
  220.     newInterfacesPB.pFullConfigDescriptor = nil;
  221.     
  222.     InitParamBlock(device, &newInterfacesPB.pb);
  223.     newInterfacesPB.pb.usbRefcon = kGetFullConfiguration0;            /* Start out at first state */
  224.     
  225. //    DebugStr("\pIn Composite Driver");
  226.     CompositeDeviceInitiateTransaction(&newInterfacesPB.pb);
  227. }
  228.  
  229.  
  230.